"""
取消订单
"""
import time
import os
import sys
import django
import datetime

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, BASE_DIR)
os.environ['DJANGO_SETTINGS_MODULE'] = 'finance_c2c.settings'
django.setup()

from apps.supply_order.models import WomaiOrder
from apps.czb.models import Orders


def cancel_order():
    # 加油
    delta = datetime.timedelta(minutes=15)
    start_create_time = datetime.datetime.now() - delta
    cancel_orders = Orders.objects.filter(create_time__lte=start_create_time,
                                          result=0)  # 需要取消的订单
    cancel_orders.update(
        result=101
    )
    # 购物
    WomaiOrder.objects.cancel_order()
    print("finish")